package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.HotelCatalog;
import cn.wolfcode.trip.base.domain.HotelIndent;
import cn.wolfcode.trip.base.query.HotelQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.*;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hotels")
public class HotelController {

   @Autowired
   private IHotelService hotelService;
   @Autowired
   private IHotelCatalogService hotelCatalogService;
   @Autowired
   private IUserHotelService userHotelService;




    /*
     *查询对应id的购物车内容
     * 资源:/shoppings
     * 动作:GET
     * 参数:currentPage=x
     **/
//    @GetMapping
//    public Object GetShopping(Long[] ids){
//        return shoppingTrolleyService.bathchGet(ids);
//    }










    /*
     * 查询对应订单id的酒店订单信息
     * 资源:/hotels/{id}/hotelId
     * 动作:GET
     * 参数:
     * */
    @GetMapping("/{id}/hotelId")
    public Object getHotelByHotelId(@PathVariable Long id){

        return userHotelService.selectByHotelId(id);

    }







    /*
     * 查询对应用户id的酒店订单信息
     * 资源:/hotels/{id}/userId
     * 动作:GET
     * 参数:keyword
     * */
    @GetMapping("/{id}/userId")
    public Object getHotelById(@PathVariable Long id, QueryObject qo){

        return userHotelService.selectByUserId(id,qo);

    }







    /*
     * 查询对应订单号的订单信息
     * 资源:/hotels/recommend
     * 动作:GET
     * 参数:keyword
     * */
    @GetMapping("/{orderNumber}")
    public Object getHotelByRecommend(@PathVariable String orderNumber){
       return userHotelService.selectByUUID(orderNumber);
    }





    /*
     *保存酒店订单信息
     * 资源:/hotels/hotelOrders
     * 动作:POST
     * 参数:UserOrder
     **/
    @PostMapping("/hotelOrders")
    public Object saveHotelOrder(HotelIndent hotelIndent){
        userHotelService.saveOrUpdate(hotelIndent);
        return new JSONResult();
    }



    /*
     * 查询推荐的酒店
     * 资源:/hotels/recommend
     * 动作:GET
     * 参数:keyword
     * */
    @GetMapping("/recommend")
    public Object getHotelByRecommend(HotelQueryObject qo){
        List<HotelCatalog> list = hotelCatalogService.selectByRecommend(qo);

        return list;
    }


   /*
    * 查询对应酒店名的酒店
    * 资源:/hotels/hotelName
    * 动作:GET
    * 参数:keyword
    * */
   @GetMapping("/hotelName")
   public Object getHotelByName(HotelQueryObject qo){
      PageInfo result = hotelCatalogService.query(qo);
      return result;
   }









   /*
    * 通过类型的id获取酒店详情
    * 资源:/hotels/catalogs/hotelId
    * 动作:GET
    * 参数:state=0&pageSize=2
    * */
   /*@GetMapping("/catalog/{hotelId}")
   public Object getcatal(HotelQueryObject qo,Long hotelId){
      PageInfo result = hotelCatalogService.list(qo,hotelId);
      return result;
   }*/

   /*
    * 获取
    * 资源:/hotels/catalogs
    * 动作:GET
    * 参数:state=0&pageSize=2
    * */
   @GetMapping("/catalogs")
   public Object getcata(HotelQueryObject qo){
      PageInfo result = hotelCatalogService.query(qo);
      return result;
   }

   /*
    * 获取酒店的内容(返回的是酒店内容)
    * 资源:/hotels/catalogs
    * 动作:GET
    * 参数:
    * */
   /*@GetMapping(value = "/{id}",produces = "text/html;charset=utf-8")
   public Object getcatalogs(@PathVariable Long id){
      return hotelCatalogService.listById(id);
   }*/

   /*
   * 获取单个酒店内容(返回的是酒店详情)
   * 资源:/hotels/catalogs/{id}
   * 动作:GET
   * 参数:
   * */
   @GetMapping("/catalogs/{id}")
   public Object getContent(@PathVariable Long id){
      HotelCatalog hotelCatalog = hotelCatalogService.get(id);
      return hotelCatalog;
   }

   /*
   * 获取对应类型的酒店内容
   * 资源:/hotels
   * 动作:get
   * 参数:
   * */
   @GetMapping
   public Object getCatalogs(HotelQueryObject qo){
      return hotelService.query(qo);
   }
}
